﻿using ConverterSystems.ServiceModel;
using Opc.Ua;
using Opc.Ua.Client;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Net;
using System.Net.Security;
using System.Runtime.CompilerServices;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace ITXHWEB.Models
{
    public partial class ABFOLGEModel : ITXModel
    {
        public ABFOLGEModel(ABFOLGEModel _MABF)
        {
            WRUNID = Guid.NewGuid().ToString();
            JP01 = "0";
            JP02 = "0";
            JP03 = "0";
            JP04 = "0";
            JP05 = "0";
            IsPDCReady = false;
            IsABPReady = false;
            IsAMReady = false;
            IsSTEPReady = false;
            IsStaffReady = false;
            IsEndReady = false;            
            IsStart = false;
            IsGotABE = true;
            ABPAUF = "";
            MACHINEID = "";
            STAFF = "";
            KRS = "";
            LFD = "";
            POS = "";
            FSTEP = "";
            MAM = new AMSTAMMModel();
            QTY = 0.0;
            DTSTART = "";
            TMSTART = "";
            DTEND = "";
            TMEND = "";
            PDCTYPE = _MABF.PDCTYPE;
            PROG = "ITXPDC";
            MABP = null;
            ABES = null;
            MKFTP = "0000";
            ABFME = "1";
            BMAUF = "";
            BLENG = 0;
            NEWUSER = _MABF.NEWUSER;
            ABFAGANG = "";
            
        }
        public void SETUP(ABFOLGEModel _MABF)
        {
            switch (PDCTYPE)
            {
                case "1NMS":
                    IsStart = true;
                    IsAMReady = true;
                    MAM.MKRS = _MABF.MAM.MKRS;
                    MAM.MLFD = _MABF.MAM.MLFD;
                    MAM.MPOS = _MABF.MAM.MPOS;
                    MAM.KKRS = _MABF.MAM.KKRS;
                    MAM.KKST = _MABF.MAM.KKST;
                    break;
                case "1S":
                    IsStart = true;
                    break;
            }
        }
        private UaSession _UAClient;
        public UaSession UAClient
        {
            get
            {
                if(_UAClient == null)
                {

                    var config = new ApplicationConfiguration()
                    {
                        ApplicationName = "ConverterSystems.TestClient",
                        ApplicationType = ApplicationType.Client,
                        SecurityConfiguration = new SecurityConfiguration { ApplicationCertificate = new CertificateIdentifier { StoreType = @"Windows", StorePath = @"CurrentUser\My", SubjectName = Utils.Format(@"CN={0}, DC={1}", "ConverterSystems.TestClient", System.Net.Dns.GetHostName()) }, TrustedPeerCertificates = new CertificateTrustList { StoreType = @"Windows", StorePath = @"CurrentUser\TrustedPeople", }, NonceLength = 32, AutoAcceptUntrustedCertificates = true },
                        TransportConfigurations = new TransportConfigurationCollection(),
                        TransportQuotas = new TransportQuotas { OperationTimeout = 15000 },
                        ClientConfiguration = new ClientConfiguration { DefaultSessionTimeout = 60000 }
                    };
                    _UAClient = new UaSession(config, "opc.tcp://" + Dns.GetHostName() + ":51212");
                }
                return _UAClient;
            }
        }
        public ABFOLGEModel()
        {
            WRUNID =Guid.NewGuid().ToString();
            JP01 =  "0";
            JP02 =  "0";
            JP03 =  "0";
            JP04 =  "0";
            JP05 = "0";
            IsPDCReady = false;
            IsABPReady = false;
            IsAMReady = false;
            IsSTEPReady = false;
            IsStaffReady = false;
            IsStart = false;
            IsEndReady = false;
            IsGotABE = true;
            ABPAUF = "";
            MACHINEID = "";
            STAFF = "";
            KRS = "";
            LFD = "";
            POS = "";
            FSTEP = ""; 
            QTY = 0.0;
            QTYPROD = 0.0;
            DTSTART = "";
            TMSTART = "";
            DTEND = "";
            TMEND = "";
            PDCTYPE = "";
            PROG = "ITXPDC";
            MABP = null;
            ABES = null;
            MAM = new AMSTAMMModel();
            MKFTP = "0000";
            ABFME = "1";
            STATUS = " ";
            BMAUF = "";
            BLENG = 0;
            ABFAGANG = ""; 
                // Step 3 - Create a model having a property for each item you wish to monitor
                var model = new ITXModel(UAClient);
                 
                //model.PropertyChanged += (s, e) => Console.WriteLine("{0}: {1}", e.PropertyName, s.GetType().GetProperty(e.PropertyName).GetValue(s));
                Console.WriteLine("Press any key to exit...");
                Console.ReadKey(true);
             
        }


        public AMSTAMMModel MAM { get; set; }

        public ABPOSModel MABP { get; set; }
        public ABARTEModel MABE { get; set; }
        public List<ABARTEModel> ABES { get; set; }
        
        [Display(Name = "生产单")]
        [Required(ErrorMessage = "必须输入生产单")]
        [StringLength(11)]
        public string ABPAUF { get; set; }


        [Display(Name = "步骤")]
        [Required(ErrorMessage = "必须输入步骤")]
        public string FSTEP { get; set; }
      

        [Display(Name = "机台")]
        [Required(ErrorMessage = "必须输入机台")]
         
        public string MACHINEID { get; set; } 
  
        [Required]
        [Display(Name = "MTR")]
        public double QMTR { get; set; }
        [Required]
        [Display(Name = "YD")]
        public double QYD { get; set; }
        [Required]
        [Display(Name = "KG")]
        public double QKG { get; set; }
        [Display(Name = "轴长")]
        public double BLENG { get; set; }
        
         [Display(Name = "数量")]
        public double QTY { get; set; }
        [Display(Name = "已产出")]
        public double QTYPROD { get; set; }
        [Display(Name = "计划量")]
        public double PLANQTY { get; set; }
        [Display(Name = "轴号")]
        public string BMAUF { get; set; }
        [Display(Name = "轴")]
        public string BKRS { get; set; }
        [Display(Name = "号")]
        public string BLFD { get; set; }
        [Display(Name = "分批")]
        public string MKFTP { get; set; }
        [Display(Name = "品种/色号")]
        public string VFART { get; set; }
        [Display(Name = "KRS")]
        public string KRS { get; set; }
        [Display(Name = "LFD")]
        public string LFD { get; set; }
        [Display(Name = "POS")]
        public string POS { get; set; }
        [Display(Name = "类型")]
        public string WAKZ { get; set; }
        [Display(Name = "品种")]
        public string ART { get; set; }
        [Display(Name = "var")]
        public string VAR { get; set; }
        [Display(Name = "色号")]
        public string FARBE { get; set; }
        [Display(Name = "开始日期")]
        [StringLength(8)]
        public string DTSTART { get; set; }
        [Display(Name = "开始时间")]
       
        public string TMSTART { get; set; }

        [Display(Name = "结束日期")]
        [StringLength(8)]
        public string DTEND { get; set; }
        [Display(Name = "结束时间")] 
        public string TMEND { get; set; }
        [Display(Name = "状态")] 
        public string STATUS { get; set; }
        [Display(Name = "类型")]
        public string PDCTYPE { get; set; } 
        [Display(Name = "加工")]
        public string ABFAGANG { get; set; }
        [Display(Name = "ABFFIX")]
        public string ABFFIX { get; set; }
        [Display(Name = "ABFMANUELKZ")]
        public string ABFMANUELKZ { get; set; }
        [Display(Name = "ABFEVARHNR")]
        public string ABFEVARHNR { get; set; }
        [Display(Name = "ABFEVARUNR")]
        public string ABFEVARUNR { get; set; }
        [Display(Name = "获取设定")]
        public bool IsGotABE { get; set; }
        [Display(Name = "已开始")]
        public bool IsStart { get; set; }
        [Display(Name = "已结束")]
        public bool IsEnd { get; set; }
        [Display(Name = "可以采集")]
        public bool IsPDCReady { get; set; }
        [Display(Name = "生产单确定")]
        public bool IsABPReady { get; set; }
        [Display(Name = "挡车工确定")]
        public bool IsStaffReady { get; set; }
        [Display(Name = "计划结束")]
        public bool IsEndReady { get; set; }
        
        [Display(Name = "设备已扫描")]
        public bool IsAMReady { get; set; }
        [Display(Name = "步骤准备好")]
        public bool IsSTEPReady { get; set; } 
         [Display(Name = "ABFME")]
        public string ABFME { get; set; }
        [Display(Name = "JP01")]
        public string JP01 { get; set; }
        [Display(Name = "JP02")]
        public string JP02 { get; set; }
        [Display(Name = "JP03")]
        public string JP03 { get; set; }
        [Display(Name = "JP04")]
        public string JP04 { get; set; }
        [Display(Name = "JP05")]
        public string JP05 { get; set; }
       
        [Display(Name = "PROG")]
        public string PROG { get; set; }
         

    }
}
